package com.wugh.fast.generator;


import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;

/**
 * 说明:
 *
 * @author wugh
 * @date 2019-07-03 10:18
 */
@Getter
public class AnnotationParser {
    private String annotationStr;
    private FullyQualifiedJavaType fullyQualifiedJavaType;
    private String parameter = "";

    public AnnotationParser(String annotationStr) {
        if (StringUtils.isNotBlank(annotationStr)) {
            annotationStr = annotationStr.trim();
            this.annotationStr = annotationStr;
            String fullyQualifiedJavaTypeStr = annotationStr;
            int i = annotationStr.indexOf("(");
            if (i != -1) {
                fullyQualifiedJavaTypeStr = annotationStr.substring(0, i);
                this.parameter = annotationStr.substring(i);
            }
            this.fullyQualifiedJavaType = new FullyQualifiedJavaType(fullyQualifiedJavaTypeStr);
        }
    }

    public String getAnnotation() {
        return "@" + fullyQualifiedJavaType.getShortName() + parameter;
    }
}
